﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Office.OneNote
{
    internal sealed class TwoWayMap<A, B>
    {
        private readonly Dictionary<A, B> _a2b = new Dictionary<A, B>();
        private readonly Dictionary<B, A> _b2a = new Dictionary<B, A>();

        public void Add(A a, B b)
        {
            _a2b[a] = b;
            _b2a[b] = a;
        }

        public A this[B key]
        {
            get { return _b2a[key]; }
        }

        public B this[A key]
        {
            get { return _a2b[key]; }
        }

        public bool Contains(A key)
        {
            return _a2b.ContainsKey(key);
        }

        public bool Contains(B key)
        {
            return _b2a.ContainsKey(key);
        }

        public bool TryGetValue(A key, out B value)
        {
            return _a2b.TryGetValue(key, out value);
        }

        public bool TryGetValue(B key, out A value)
        {
            return _b2a.TryGetValue(key, out value);
        }
    }
}
